package com.shushan.invitecode;

import android.media.Image;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shushan.base.BaseActivity;
import com.shushan.base.ScreenManager;
import com.shushan.invitecode.adapter.RetroCardAdapter;
import com.shushan.invitecode.bean.InviteBean;
import com.shushan.pages.OpenVipSpendActivity;
import com.shushan.shushanbao.R;
import com.shushan.ui.OffsetRecyclerDivider;
import com.shushan.util.DensityUtil;
import com.shushan.util.DialogUtil;
import com.shushan.util.Session;

/**
 * @ClassName: MyRetroactiveCardActivity
 * @Desciption: //我的补签卡界面
 * @author: zhangshihao
 * @date: 2018-09-15
 */
public class MyRetroactiveCardActivity extends BaseActivity implements View.OnClickListener{

    private TextView tvGetRule;
    private RecyclerView rvRetroCard;
    private Button btnRecharge;
    private TextView tvRetroCount;
    private ImageView ivRetroCardState;
    private TextView tvNoCard;
    private LinearLayout llMyCard;
    private LinearLayout llNoCard;

    private InviteBean inviteBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScreenManager.getInstance().setStatusBar(true,this);
        setContentView(R.layout.activity_retroactive_card);

        inviteBean = (InviteBean) Session.getSession().get("gInviteBean");

        initView();

        initData();
    }

    private void initView(){
        tvGetRule = findViewById(R.id.tv_retro_card_get_rule);
        tvGetRule.setOnClickListener(this);
        rvRetroCard = findViewById(R.id.rv_retro_card);
        rvRetroCard.setLayoutManager(new LinearLayoutManager(this));
        rvRetroCard.addItemDecoration(new OffsetRecyclerDivider(DensityUtil.dip2px(this,10f)));
        btnRecharge = findViewById(R.id.btn_recharge);
        btnRecharge.setOnClickListener(this);
        tvRetroCount = findViewById(R.id.tv_retro_card_count);
        ivRetroCardState = findViewById(R.id.iv_retro_card_state);
        tvNoCard = findViewById(R.id.tv_no_card);
        llMyCard = findViewById(R.id.ll_my_card);
        llNoCard = findViewById(R.id.ll_no_card);
    }

    private void initData(){
        if(inviteBean.patch_card == 0){
            ivRetroCardState.setImageResource(R.drawable.bg_no_retro_card);
            tvNoCard.setVisibility(View.VISIBLE);
            llNoCard.setVisibility(View.VISIBLE);
            llMyCard.setVisibility(View.GONE);
            rvRetroCard.setVisibility(View.GONE);
        }else {
            tvRetroCount.setText(inviteBean.patch_card + "张");
            RetroCardAdapter adapter = new RetroCardAdapter(inviteBean);
            adapter.setOnUseBtnClickListener(new RetroCardAdapter.OnUseBtnClickListener() {
                @Override
                public void onUseBtnClick() {
                    startActivity(InviteCalendarActivity.class);
                    onBackAction();
                }
            });
            rvRetroCard.setAdapter(adapter);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_retro_card_get_rule:
                DialogUtil.showRetroRuleDialog(this);
                break;
            case R.id.btn_recharge:
                startActivity(OpenVipSpendActivity.class);
                break;
        }
    }

}
